/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package ria.provider;

import java.util.ArrayList;
import java.util.Collection;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;

import org.eclipse.emf.edit.provider.ChangeNotifier;
import org.eclipse.emf.edit.provider.ComposeableAdapterFactory;
import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.provider.IChangeNotifier;
import org.eclipse.emf.edit.provider.IDisposable;
import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.emf.edit.provider.INotifyChangedListener;
import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
import org.eclipse.emf.edit.provider.ITreeItemContentProvider;

import ria.util.RiaAdapterFactory;

/**
 * This is the factory that is used to provide the interfaces needed to support Viewers.
 * The adapters generated by this factory convert EMF adapter notifications into calls to {@link #fireNotifyChanged fireNotifyChanged}.
 * The adapters also support Eclipse property sheets.
 * Note that most of the adapters are shared among multiple instances.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public class RiaItemProviderAdapterFactory extends RiaAdapterFactory implements ComposeableAdapterFactory, IChangeNotifier, IDisposable {
	/**
	 * This keeps track of the root adapter factory that delegates to this adapter factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ComposedAdapterFactory parentAdapterFactory;

	/**
	 * This is used to implement {@link org.eclipse.emf.edit.provider.IChangeNotifier}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected IChangeNotifier changeNotifier = new ChangeNotifier();

	/**
	 * This keeps track of all the supported types checked by {@link #isFactoryForType isFactoryForType}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected Collection<Object> supportedTypes = new ArrayList<Object>();

	/**
	 * This constructs an instance.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public RiaItemProviderAdapterFactory() {
		supportedTypes.add(IEditingDomainItemProvider.class);
		supportedTypes.add(IStructuredItemContentProvider.class);
		supportedTypes.add(ITreeItemContentProvider.class);
		supportedTypes.add(IItemLabelProvider.class);
		supportedTypes.add(IItemPropertySource.class);
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.Widget} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WidgetItemProvider widgetItemProvider;

	/**
	 * This creates an adapter for a {@link ria.Widget}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createWidgetAdapter() {
		if (widgetItemProvider == null) {
			widgetItemProvider = new WidgetItemProvider(this);
		}

		return widgetItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.UIModel} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected UIModelItemProvider uiModelItemProvider;

	/**
	 * This creates an adapter for a {@link ria.UIModel}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createUIModelAdapter() {
		if (uiModelItemProvider == null) {
			uiModelItemProvider = new UIModelItemProvider(this);
		}

		return uiModelItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.WLayout} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WLayoutItemProvider wLayoutItemProvider;

	/**
	 * This creates an adapter for a {@link ria.WLayout}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createWLayoutAdapter() {
		if (wLayoutItemProvider == null) {
			wLayoutItemProvider = new WLayoutItemProvider(this);
		}

		return wLayoutItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.Event} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected EventItemProvider eventItemProvider;

	/**
	 * This creates an adapter for a {@link ria.Event}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createEventAdapter() {
		if (eventItemProvider == null) {
			eventItemProvider = new EventItemProvider(this);
		}

		return eventItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.WControl} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WControlItemProvider wControlItemProvider;

	/**
	 * This creates an adapter for a {@link ria.WControl}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createWControlAdapter() {
		if (wControlItemProvider == null) {
			wControlItemProvider = new WControlItemProvider(this);
		}

		return wControlItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.WDataView} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WDataViewItemProvider wDataViewItemProvider;

	/**
	 * This creates an adapter for a {@link ria.WDataView}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createWDataViewAdapter() {
		if (wDataViewItemProvider == null) {
			wDataViewItemProvider = new WDataViewItemProvider(this);
		}

		return wDataViewItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.WNavigation} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WNavigationItemProvider wNavigationItemProvider;

	/**
	 * This creates an adapter for a {@link ria.WNavigation}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createWNavigationAdapter() {
		if (wNavigationItemProvider == null) {
			wNavigationItemProvider = new WNavigationItemProvider(this);
		}

		return wNavigationItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.WService} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WServiceItemProvider wServiceItemProvider;

	/**
	 * This creates an adapter for a {@link ria.WService}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createWServiceAdapter() {
		if (wServiceItemProvider == null) {
			wServiceItemProvider = new WServiceItemProvider(this);
		}

		return wServiceItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.WInput} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected WInputItemProvider wInputItemProvider;

	/**
	 * This creates an adapter for a {@link ria.WInput}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createWInputAdapter() {
		if (wInputItemProvider == null) {
			wInputItemProvider = new WInputItemProvider(this);
		}

		return wInputItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.Accordion} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected AccordionItemProvider accordionItemProvider;

	/**
	 * This creates an adapter for a {@link ria.Accordion}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createAccordionAdapter() {
		if (accordionItemProvider == null) {
			accordionItemProvider = new AccordionItemProvider(this);
		}

		return accordionItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.ThumbDrag} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected ThumbDragItemProvider thumbDragItemProvider;

	/**
	 * This creates an adapter for a {@link ria.ThumbDrag}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createThumbDragAdapter() {
		if (thumbDragItemProvider == null) {
			thumbDragItemProvider = new ThumbDragItemProvider(this);
		}

		return thumbDragItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.HSlider} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected HSliderItemProvider hSliderItemProvider;

	/**
	 * This creates an adapter for a {@link ria.HSlider}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createHSliderAdapter() {
		if (hSliderItemProvider == null) {
			hSliderItemProvider = new HSliderItemProvider(this);
		}

		return hSliderItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.TileList} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected TileListItemProvider tileListItemProvider;

	/**
	 * This creates an adapter for a {@link ria.TileList}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createTileListAdapter() {
		if (tileListItemProvider == null) {
			tileListItemProvider = new TileListItemProvider(this);
		}

		return tileListItemProvider;
	}

	/**
	 * This keeps track of the one adapter used for all {@link ria.LinkButtom} instances.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected LinkButtomItemProvider linkButtomItemProvider;

	/**
	 * This creates an adapter for a {@link ria.LinkButtom}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter createLinkButtomAdapter() {
		if (linkButtomItemProvider == null) {
			linkButtomItemProvider = new LinkButtomItemProvider(this);
		}

		return linkButtomItemProvider;
	}

	/**
	 * This returns the root adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ComposeableAdapterFactory getRootAdapterFactory() {
		return parentAdapterFactory == null ? this : parentAdapterFactory.getRootAdapterFactory();
	}

	/**
	 * This sets the composed adapter factory that contains this factory.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setParentAdapterFactory(ComposedAdapterFactory parentAdapterFactory) {
		this.parentAdapterFactory = parentAdapterFactory;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean isFactoryForType(Object type) {
		return supportedTypes.contains(type) || super.isFactoryForType(type);
	}

	/**
	 * This implementation substitutes the factory itself as the key for the adapter.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Adapter adapt(Notifier notifier, Object type) {
		return super.adapt(notifier, this);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object adapt(Object object, Object type) {
		if (isFactoryForType(type)) {
			Object adapter = super.adapt(object, type);
			if (!(type instanceof Class<?>) || (((Class<?>)type).isInstance(adapter))) {
				return adapter;
			}
		}

		return null;
	}

	/**
	 * This adds a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void addListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.addListener(notifyChangedListener);
	}

	/**
	 * This removes a listener.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void removeListener(INotifyChangedListener notifyChangedListener) {
		changeNotifier.removeListener(notifyChangedListener);
	}

	/**
	 * This delegates to {@link #changeNotifier} and to {@link #parentAdapterFactory}.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void fireNotifyChanged(Notification notification) {
		changeNotifier.fireNotifyChanged(notification);

		if (parentAdapterFactory != null) {
			parentAdapterFactory.fireNotifyChanged(notification);
		}
	}

	/**
	 * This disposes all of the item providers created by this factory. 
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void dispose() {
		if (widgetItemProvider != null) widgetItemProvider.dispose();
		if (uiModelItemProvider != null) uiModelItemProvider.dispose();
		if (wLayoutItemProvider != null) wLayoutItemProvider.dispose();
		if (eventItemProvider != null) eventItemProvider.dispose();
		if (wControlItemProvider != null) wControlItemProvider.dispose();
		if (wDataViewItemProvider != null) wDataViewItemProvider.dispose();
		if (wNavigationItemProvider != null) wNavigationItemProvider.dispose();
		if (wServiceItemProvider != null) wServiceItemProvider.dispose();
		if (wInputItemProvider != null) wInputItemProvider.dispose();
		if (accordionItemProvider != null) accordionItemProvider.dispose();
		if (thumbDragItemProvider != null) thumbDragItemProvider.dispose();
		if (hSliderItemProvider != null) hSliderItemProvider.dispose();
		if (tileListItemProvider != null) tileListItemProvider.dispose();
		if (linkButtomItemProvider != null) linkButtomItemProvider.dispose();
	}

}
